import { Act } from "../../type/actType.js";

export const useCommand: Act = {
  name: "useCommand",
  description: '执行一条游戏指令，如果要执行命令必须使用这个行动，注意需要"/"前缀',
  params: [
    {
      type: "string",
      name: "command",
      description: '要执行的指令，比如"/weather clear"',
    },
  ],
  perform: (_bot, args): void => {
    const bot = _bot._bot;
    let command = args["command"] as string;
    if (!bot) {
      throw new Error("Bot 不存在");
    }
    if (!command || command.trim().length === 0) {
      throw new Error("指令不能为空");
    }
    if (command[0] !== "/") command = "/" + command;
    bot.chat(`${command.trim()}`);
  },
};
